package com.bowen.demo.demo008.method3;

/**
 * <h3>java-study</h3>
 * <p>深拷贝</p>
 * 在Java语言中，如果需要实现深克隆，可以通过覆盖Object类的clone()方法实现，也可以通过序列化(Serialization)等方式来实现。
 * @author : zhang.bw
 * @date : 2021-04-29 14:01
 **/

public class Person implements Cloneable{

	public String pname;
	public int page;
	public Address address;
	public Person() {}

	public Person(String pname,int page){
		this.pname = pname;
		this.page = page;
		this.address = new Address();
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		Person p = (Person) super.clone();
		p.address = (Address) address.clone();
		return p;
	}

	public void setAddress(String provices,String city ){
		address.setAddress(provices, city);
	}
	public void display(String name){
		System.out.println(name+":"+"pname=" + pname + ", page=" + page +","+ address);
	}

	public String getPname() {
		return pname;
	}

	public void setPname(String pname) {
		this.pname = pname;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

}
